package org.ladybug.service.admin;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

//import javax.crypto.SecretKeyFactory;
//import javax.crypto.spec.PBEKeySpec;

import org.apache.commons.lang.time.DateFormatUtils;
import org.ladybug.dao.persistence.Utente;
import org.skins.io.HexReader;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

public class AdminServiceImplTest extends
		AbstractDependencyInjectionSpringContextTests {

	
	
	private AdminService adminService;
	
	public void testInsertNewUtente() throws NoSuchAlgorithmException{
		Utente utente = new Utente();
		utente.setNickname("patata");
		
		byte[] password = new StringBuffer(utente.getNickname()).append("pardo").toString().getBytes();
		password = MessageDigest.getInstance("SHA").digest(password);
		utente.setPassword(HexReader.bytesToHex(password));
		utente.setDataInizio(new Date());
		utente.setIsSospeso(false);
		adminService.insertNewUtente(utente);
	}

//	public void testGetUtenteByCredential() {
//		Utente utente = new Utente();
//		utente.setNickname("patata");
//		utente.setPassword("pardo");
//		Utente u = adminService.getUtenteByCredential(utente);
//		DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.DATE_FIELD,Locale.ITALIAN);
//		System.out.println(df.format(u.getDataInizio()));
//	}
//	
	
	public void testSospendiUtente(){
		Utente utente = new Utente();
		utente.setNickname("pardo");
		
		
	}
	
	public void testFindUtenteByNickName(){
		Utente utente = new Utente();
		utente.setNickname("pardo");
		utente = getAdminService().findUtenteByNickname(utente);
		System.out.println(utente.getPassword());
	}
	
	
	public AdminService getAdminService() {
		return adminService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	protected String[] getConfigLocations() {
		
		return new String[]{"file:c:/progetti/workspace/ladybug/src/web/ladybug/WEB-INF/application-beans.xml"};
	}
	
	
	
	

}
